<?php

namespace App\Http\Controllers\Api;

use App\logic\DataProcessing;
use App\Models\DoctorModel;
use App\servers\BaiDuTextFilter;
use Illuminate\Http\Request;


class DoctorController extends BaseController
{

    /**
     * ww
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     * 医生添加
     * ww
     */
    public function addDoctor(Request $request){

        try {
            $param=$request->post();
            $request->validate([
                'name'=>'required',
                'sex'=>'required',
                'age'=>'required',
                'status'=>'required',
                'department'=>'required',
                'mobile'=>'required',
                'practicing_certificate'=>'required',
                'introduction'=>'required',
            ],[
                'name.required'=>'医生姓名不得为空',
                'sex.required'=>'医生性别不得为空',
                'age.required'=>'医生年龄不得为空',
                'status.required'=>'医生状态不得为空',
                'department.required'=>'医生所属科室不得为空',
                'mobile.required'=>'医生号码不得为空',
                'practicing_certificate.required'=>'执业证书不得为空',
                'introduction.required'=>'医生简介不得为空',
            ]);
            //点用百度云内容审核
            (new BaiDuTextFilter())->textFilter($param['name']);
            DataProcessing::adds($param);
            return $this->witejson(0,'','添加成功');
        }catch (\Exception $e){
            return $this->witejson(1,'',$e->validator->errors()->first());
        }
    }

    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     * 医生删除
     * ww
     */
    public function delData(Request $request)
    {
         try {
            $id=$request->get('id');
            DataProcessing::dels($id);
            return $this->witejson(0,'','删除成功');
         }catch (\Exception $e){
            return $this->witejson(1,'',$e->validator->errors()->first());
         }
    }

    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     * 医生列表
     * ww
     */

    public function listDoctor(Request $request)
    {
        try {
           $data=DoctorModel::listDoctor();
            return $this->witejson(0,$data,'ok');
        }catch (\Exception $e){
            return $this->witejson(1,'',$e->validator->errors()->first());
        }
    }

    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     * 医生修改
     * ww
     */
    public function updateDoctor(Request $request)
    {
        try {
            $param=$request->post();
            $id=$param['id'];
            $res=DataProcessing::updates($id,$param);
            return $this->witejson(0,'','修改成功');
        }catch (\Exception $e){
            return $this->witejson(1,'',$e->validator->errors()->first());
        }
    }

    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     * 医生详情
     * ww
     */

    public function detailsDoctor(Request $request)
    {
        try {
            $id=$request->get('id');
            $data=DoctorModel::detailsDoctor(['id'=>$id]);
            return $this->witejson(0,$data,'ok');
        }catch (\Exception $e){
            return $this->witejson(1,'',$e->validator->errors()->first());
        }
    }

    public function test()
    {
//        config('code.baiduText.ApiKey'), config('code.baiduText.secretKey')
        $code=config('code.baiduText.ApiKey');
        dd($code);
    }
}
